package org.yoki.edu.portal.web.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by xuyue on 2017/12/1.
 */
public class JudgeBrowserUtils {

    /**
     * 浏览器类型
     */
    public static String[] BROWSER_AGENTS = {"mqqbrowser", "applewebkit",
            "avant", "360", "tencenttraveler", "maxthon ", "windows", "firefox", "intelmacosx", "opera"
            , "metasr", "linux", "mobilesafari", "qqbrowser", "uc", "chrome", "lbbrowser", "taobrowser"};

    /**
     * 判断是否是手机浏览器
     *
     * @param request 请求
     * @return 是否是浏览器
     */
    public static boolean judge(HttpServletRequest request) {
        boolean isBrowser = false;
        String userAgent = request.getHeader("User-Agent");
        if (userAgent != null && userAgent.length() > 0) {
            String change = userAgent.toLowerCase();
            for (String mobileAgent : BROWSER_AGENTS) {
                if (change.indexOf(mobileAgent.toLowerCase()) > 0) {
                    isBrowser = true;
                    break;
                }
            }
        }
        return isBrowser;
    }
}
